package recursion;

public class PascalTriangleBasic {
    public static int getNum(int row, int column) {
        if (column == 0 || column == row) {
            return 1;
        }
        return getNum(row - 1, column) + getNum(row - 1, column - 1);
    }

    // (n-1-i)*2 (高度-1-行索引)*2为对其空格数 *2是因为数字占四格
    public static void printSpace(int height, int row) {
        int num = (height - 1 - row) * 2;
        for (int j = 0; j < num; j++) {
            System.out.print(" ");
        }
    }

    public static void printPascalTriangle(int num) {
        for (int row = 0; row < num; row++) {
            printSpace(num, row);
            for (int column = 0; column <= row; column++) {
                System.out.printf("%4d", getNum(row, column));
            }
            System.out.println();
        }
    }

    public static void main(String[] args) {
        printPascalTriangle(50);
    }
}
